package com.share.auth.controller;

import com.share.auth.service.UserLoginService;
import com.share.common.core.domain.R;
import com.share.common.security.service.TokenService;
import com.share.user.api.model.LoginUserInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/h5")
@Tag(name = "小程序扫码登录接口")
public class WXLoginController {

    @Autowired
    private UserLoginService userLoginService;

    @Autowired
    private TokenService tokenService;

    @GetMapping("/login/{code}")
    public R<?> login(@PathVariable String code) {
        // 小程序用户登录
        LoginUserInfo loginUserInfo = userLoginService.login(code);

        // 获取Token
        return R.ok(tokenService.createLoginToken(loginUserInfo));
    }

}
